package com.example.pinkcat.activity.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.pinkcat.R;
import com.example.pinkcat.activity.VideoPinkcat;
import com.example.pinkcat.activity.api.entity.VideoEntity;
import com.rishabhharit.roundedimageview.RoundedImageView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class VAMF_recyleview_adapter extends RecyclerView.Adapter<VAMF_recyleview_adapter.ViewHolder>{
    private final Context context;
    int pl_numbers;
    int type=0;//"0综艺","1动漫","2电视剧","3电影"
    List<VideoEntity> videoEntities=new ArrayList<>();

    //构造方法
    public VAMF_recyleview_adapter(Context context, int pl_numbers, int type){
        this.context=context;
        this.pl_numbers=pl_numbers;
        this.type=type;
    }

    public void setData(List<VideoEntity> data){
        this.videoEntities=data;
        notifyDataSetChanged();
    }



    //内部内
    public static class ViewHolder extends RecyclerView.ViewHolder{

        Spinner spinner_change_viewSate;

        //tv
        RoundedImageView face_animation;
        TextView title_animation;
        TextView time_animation;
        TextView type_animation;
        TextView area_animation;
        TextView videoType_animation;
        TextView play_num;

        View clicklayout;
        //寻找声明布局控件
        public ViewHolder(View view) {
            super(view);
            spinner_change_viewSate=view.findViewById(R.id.change_viewState);

            face_animation=view.findViewById(R.id.face_animation);
            title_animation=view.findViewById(R.id.title_animation);
            time_animation=view.findViewById(R.id.time_animation);
            type_animation=view.findViewById(R.id.type_animation);
            area_animation=view.findViewById(R.id.area_animation);
            videoType_animation=view.findViewById(R.id.videoType_animation);
            play_num=view.findViewById(R.id.play_num);
            clicklayout=view.findViewById(R.id.clicklayout);
        }
    }
    //创建获取 view  布局
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //获取item内容
        View view;
            view= LayoutInflater.from(context).inflate(R.layout.list_animation01,parent,false);
        return new ViewHolder(view);
    }

    //绑定数据
    @SuppressLint({"CheckResult", "SetTextI18n"})
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        setDm(holder,position);
        List<String> list = new ArrayList<String>();
        list.add("添加到在看");
        list.add("添加到看过");
        ArrayAdapter<String> spinner_adapter=new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,list);
        spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        holder.spinner_change_viewSate.setAdapter(spinner_adapter);
    }

    @Override
    public int getItemCount() {
        return videoEntities.size();
    }
    void setDm(ViewHolder holder, int position){
        Glide.with(context).load(Uri.parse(videoEntities.get(position).getVideo_cover())).into(holder.face_animation);
        holder.title_animation.setText(videoEntities.get(position).getVideo_name());
        SimpleDateFormat format =  new SimpleDateFormat("yyyy");
        holder.time_animation.setText(format.format(videoEntities.get(position).getVideo_pub_time()));
        holder.type_animation.setText(videoEntities.get(position).getVideo_type());
        holder.area_animation.setText("未知地区");
        holder.videoType_animation.setText(videoEntities.get(position).getVideo_lab());
        holder.play_num.setText(String.valueOf(videoEntities.get(position).getTotalplay()));
        holder.clicklayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, VideoPinkcat.class);
                intent.putExtra("v_id",videoEntities.get(position).getVideo_id());
                intent.putExtra("up_id",videoEntities.get(position).getUser_id());
                intent.putExtra("v_link",videoEntities.get(position).getVideo_link());
                intent.putExtra("v_labs",videoEntities.get(position).getVideo_lab());
                context.startActivity(intent);
            }
        });
    }
}
